package com.itheima.stream;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Stream;

/**
 * @author Anomaly
 * @date 2023/2/6 15:39
 */
public class StreamDemo3 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        Collections.addAll(list, "张三丰", "张无忌", "周芷若", "张三丰", "赵敏", "张强");
        System.out.println(list);
        System.out.println("------------------------------------");

        list.stream().filter(s -> s.startsWith("张")).forEach(System.out::println);
        System.out.println("------------------------------------");

        long count = list.stream().filter(s -> s.length() == 2).count();
        System.out.println("count = " + count);
        System.out.println("------------------------------------");

        list.stream().limit(3).forEach(System.out::println);
        System.out.println("------------------------------------");

        list.stream().skip(2).forEach(System.out::println);
        System.out.println("------------------------------------");

        list.stream().map(s -> "黑马的：" + s).forEach(System.out::println);
        System.out.println("------------------------------------");

        Stream<String> stream1 = list.stream().filter(s -> s.startsWith("张"));
        Stream<String> stream2 = Stream.of("java", "c艹", "go");
        Stream<String> stream3 = Stream.concat(stream1, stream2);
        stream3.forEach(System.out::println);
        System.out.println("------------------------------------");

        list.stream().filter(s -> s.startsWith("张")).distinct().forEach(System.out::println);
    }
}
